/**
 * Created by sicongdu on 17-11-21.
 */
var model_user = require("./model").user;

var signup = (req, res) => {
    console.log(req.body)
    var id = req.body.id

    if (id == 0) {
        model_user.count({}, (err_count, number) => {
            if (err_count) {
                res.send("count error")
                return
            }

            var user = new model_user({
                user: req.body.user,
                id: number + 1
            });
            user.save((err, resin) => {
                if (err) {
                    res.send(err)
                    return
                } else {
                    var ret = {
                        error: 1,
                        user_id: number + 1,
                    }

                    res.send(ret)
                    return
                }
            })
        })
    }
};

module.exports = {
    signup : signup
};